<html lang="en" xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>爱打印-iprint 广告信息列表</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all" />
		<link rel="stylesheet" th:href="@{/css/public.css }" media="all" />
	</head>

	<body class="childrenBody">
		<!-- 操作列表 -->
		<blockquote class="layui-elem-quote quoteBox">
			<form class="layui-form">
				<div class="layui-inline">
					<div class="layui-input-inline">
						<input type="text" class="layui-input searchVal" placeholder="请输入搜索的内容" />
					</div>
					<a class="layui-btn search_btn" data-type="reload">搜索</a>
				</div>
				<div class="layui-inline">
					<a class="layui-btn layui-btn-normal addNews_btn">添加文章</a>
				</div>
			</form>
		</blockquote>
		<table id="infoList" lay-filter="newsList"></table>
		<!--审核状态-->
		<script type="text/html" id="infoStatus">
		{{#  if(d.state == "1"){ }}
		<span class="layui-red">发布</span>
		{{#  } else if(d.state == "0"){ }}
		<span class="layui-blue">草稿</span>
		{{#  } else { }}
			错误
		{{#  }}}
		</script>
		<script type="text/html" id="infoType">
		{{#  if(d.category == "helpinfo"){ }}
		<span class="layui-red">帮助信息</span>
		{{#  } else if(d.category == "adsinfo"){ }}
		<span class="layui-blue">广告信息</span>
		{{#  } else { }}
			错误
		{{#  }}}
		</script>
		<!--操作-->
		<script type="text/html" id="newsListBar">
		    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
		    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
	    </script>
		<script type="text/javascript" src="${pageContext.request.contextPath }/layui/layui.js"></script>
		
		<script>
			layui.use(['form','layer','laydate','table','laytpl'],function(){
			    var form = layui.form,
			        layer = parent.layer === undefined ? layui.layer : top.layer,
			        $ = layui.jquery,
			        laydate = layui.laydate,
			        laytpl = layui.laytpl,
			        table = layui.table;

		    	//新闻列表
			    var tableIns = table.render({
			        elem: '#infoList',
			        url : '/iprint/admin/getInfoList',
			        cellMinWidth : 95,
			        page : true,
			        height : "full-125",
			        limit : 20,
			        limits : [10,15,20,25],
			        id : "infoList",
			        request:{
			        	 pageName: 'currPage' //页码的参数名称，默认：page
			  			,limitName: 'pageSize' //每页数据量的参数名，默认：limit
			        },
			        where:{
			        	queryType:'adsinfo'
			        },
			        response: {
					  statusName: 'status' //数据状态的字段名称，默认：code
					  ,statusCode: 200 //成功的状态码，默认：0
					  ,countName: 'totalCount' //数据总数的字段名称，默认：count
					  ,dataName: 'list' //数据列表的字段名称，默认：data
					},
			        cols : [[
			            {type: "checkbox",  fixed:"left",width:50},
			            {field: 'id', 		title: 'ID',width:60, align:"center"},
			            {field: 'title', 	title: '文章标题',},
			            {field: 'state', 	title: '文章状态',  	align:'center',templet:"#infoStatus"},
			            {field: 'category', title: '分类', 	align:'center',templet:"#infoType"},
			            {field: 'top', 		title: '是否置顶', 	align:'center', templet:function(d){
			            	if(d.top =='1'){
				                return '<span class="layui-red">置顶中</span>'
			            	}else{
			            		return '<span class="layui-red">未置顶</span>'
			            	}
			            }},
			            {field: 'createTime', title: '发布时间', align:'center', minWidth:110},
			            {field: 'updateTime', title: '更新时间', align:'center',minWidth:110},
			            {title: '操作', width:170, templet:'#newsListBar',fixed:"right",align:"center"}
			        ]]
			    });
			
			
			    //搜索【此功能需要后台配合，所以暂时没有动态效果演示】
			    $(".search_btn").on("click",function(){
			        if($(".searchVal").val() != ''){
			            table.reload("newsListTable",{
			                page: {
			                    curr: 1 //重新从第 1 页开始
			                },
			                where: {
			                    key: $(".searchVal").val()  //搜索的关键字
			                }
			            })
			        }else{
			            layer.msg("请输入搜索的内容");
			        }
			    });
		
			    //添加文章
			    function addNews(edit){
			        var index = layui.layer.open({
			            title : "添加文章",
			            type : 2,
			            content : "addInfoPage",
			            success : function(layero, index){
			                var body = layui.layer.getChildFrame('body', index);
			                if(edit){
			                    body.find(".title").val(edit.title);
			                    body.find(".infoid").val(edit.id);
			                    body.find(".infodesc").val(edit.infodesc);
			                    body.find("#info_content").val(edit.content);
			                    body.find(".categoryaa input[value='"+edit.category+"']").prop("checked","checked");
			                    body.find(".top input[name='top'][value='"+edit.top+"']").prop("checked","checked");
			                    body.find(".infoStatus option[value='"+edit.state+"']").prop("selected","selected");
			                    form.render();
			                }
			                setTimeout(function(){
			                    layui.layer.tips('点击此处返回文章列表', '.layui-layer-setwin .layui-layer-close', {
			                        tips: 3
			                    });
			                },500)
			            }
			        })
			        
			        
			        layui.layer.full(index);
			        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
			        $(window).on("resize",function(){
			            layui.layer.full(index);
			        })
			    }
			    
			//删除文章
		    $(".addNews_btn").click(function(){
		        addNews();
		    })
		    //列表操作
		    table.on('tool(newsList)', function(obj){
		        var layEvent = obj.event,
		            data = obj.data;
		        if(layEvent === 'edit'){ //编辑
		        	$.ajax({
		        		url:"/iprint/admin/getInfo?id="+data.id,
		        		type:"GET",
		        		dataType:"json",
		        		success:function(msg){
				            addNews(msg);
		        		}
		        	});
		        } else if(layEvent === 'del'){ //删除
		            layer.msg('确定删除此条信息？', {
		            	  time: 0 //不自动关闭
		            	  ,btn: ['确定', '取消']
		            	  ,yes: function(index){
		            		  layer.close(index);
		            		  $.ajax({
					        		url:"/iprint/admin/delInfo?id="+data.id,
					        		type:"GET",
					        		dataType:"json",
					        		success:function(msg){
					        		}
					        	});
		            		  tableIns.reload();
		            	  }
		            	});
		        } else if(layEvent === 'look'){ //预览
		            layer.alert("此功能需要前台展示，实际开发中传入对应的必要参数进行文章内容页面访问")
		        }
		    });
		
		})
	</script>
</body>

</html>